package com.telecom.weixi.adapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.telecom.weixi.R;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ClientMenuAdapter extends BaseAdapter {
	List<Map<String, Object>> mClientData;
	LayoutInflater mFalter;
	
	public static final String Tag_Menu_Title = "menu_title";		//String
	public static final String Tag_Menu_Tips  = "menu_tips";		//String
	public static final String Tag_Menu_NextArrow = "next_arrow";	//drawable
	
	public ClientMenuAdapter(Context context){
		mFalter = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mClientData = new ArrayList<Map<String, Object>>();
	}
	
	public void addItem(Map<String, Object> item){
		mClientData.add(item);
	}
	
	public void clearData(){
		mClientData.clear();
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mClientData.size();
	}

	@Override
	public Object getItem(int pos) {
		// TODO Auto-generated method stub
		return mClientData.get(pos);
	}

	@Override
	public long getItemId(int pos) {
		// TODO Auto-generated method stub
		return pos;
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if(convertView != null){
			holder = (ViewHolder) convertView.getTag();
		}else{
			holder = new ViewHolder();
			convertView = mFalter.inflate(R.layout.item_client_menu, null); 
			holder.title = (TextView) convertView.findViewById(R.id.title);
			holder.tips = (TextView) convertView.findViewById(R.id.tips);
			holder.nextArrow = (ImageView) convertView.findViewById(R.id.next_arrow);
			
			convertView.setTag(holder);
		}
		
		Map<String, Object> item = mClientData.get(pos);
		holder.title.setText((CharSequence) item.get(Tag_Menu_Title));
		String tips = "  " + (String) item.get(Tag_Menu_Tips); 
		holder.tips.setText(tips);
		Drawable icon = (Drawable) item.get(Tag_Menu_NextArrow);
		if(icon != null ){
			holder.nextArrow.setBackgroundDrawable(icon);
		}
		return convertView;
	}
	
	class ViewHolder{
		TextView title;
		TextView tips;
		ImageView nextArrow;
	}

}
